<template>
  <div class="allOrderContainer">
    <div v-if="activeNameTab === 'first'">
      <!-- 订单操作 -->
      <div class="actions" style="margin-bottom: 10px">
        <div class="left">
          <el-button
            id="distribution_create_button"
            data-tracker="P8-1"
            type="primary"
            plain
            size="mini"
            @click="handleClickAdd"
            v-permission="'waybillDistribution_create'"
          >
            创建配送单</el-button
          >
          <el-dropdown
            v-permission="'waybillDistribution_import_update'"
            @command="handleWaybillMessage"
            divided
            class="operation-drop"
          >
            <el-button type="primary" plain>
              导入<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu
              class="operation-drop"
              slot="dropdown"
              style="width: 150px"
            >
              <el-dropdown-item command="3">修改配送单信息</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button
            v-permission="'waybill_distribution_stay_export'"
            type="primary"
            :loading="isLoading"
            plain
            size="mini"
            @click="handleExport('2')"
            >导出</el-button
          >
        </div>
        <div class="right" style="display: flex">
          <el-button
            type="primary"
            @click.stop.native
            icon="el-icon-refresh"
            @click="handleReset"
            data-tracker="P9-2"
            style="margin-right: 10px"
            >重置</el-button
          >
          <SettinUp
            :settype="1"
            :objSettinUpdata="objSettinUp"
            key="1"
          ></SettinUp>
        </div>
      </div>
      <div v-if="header_data_list.length > 0">
        <TableHeader
          ref="TableHeaderList_one"
          :header_data_list="header_data_list"
          :HeaderData="HeaderData"
          :propMap="propMap"
          :objheader="objheader"
          @childEvent="handleDelete"
          @orderIdNumsEvent="handleDeleteType"
        ></TableHeader>
      </div>
      <div
        style="
          display: flex;
          justify-content: flex-end;
          margin: 10px 0px 0px 0px;
        "
      >
        <el-pagination
          background
          :current-page="paginations.pageIndex"
          :page-sizes="paginations.pageSizes"
          :page-size="paginations.pageSize"
          :layout="paginations.layout"
          :total="paginations.total"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
        />
      </div>
    </div>
    <div v-if="activeNameTab === 'second'">
      <!-- 订单操作 -->
      <div class="actions" style="margin-bottom: 10px">
        <div class="left">
          <el-button
            id="distribution_complete_button"
            v-permission="'waybillDistribution_finish_update'"
            type="primary"
            plain
            data-tracker="P9-3"
            @click="handleClickSuc"
            >配送完成</el-button
          >
          <el-button
            v-permission="'waybillDistribution_delete'"
            type="primary"
            plain
            data-tracker="P9-9"
            @click="handleClickDelete"
            >删除</el-button
          >
          <el-dropdown
            v-permission="'waybillDistribution_import_update'"
            @command="handleWaybillMessage"
            divided
            class="operation-drop"
          >
            <el-button type="primary" plain>
              导入<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu
              class="operation-drop"
              slot="dropdown"
              style="width: 150px"
            >
              <el-dropdown-item command="3">修改配送单信息</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button
            v-permission="'waybill_distribution_export'"
            type="primary"
            :loading="isLoading"
            plain
            size="mini"
            @click="handleExport('0')"
            >导出</el-button
          >
        </div>
        <div class="right" style="display: flex">
          <el-button
            type="primary"
            @click.stop.native
            icon="el-icon-refresh"
            @click="handleSearchReset"
            data-tracker="P9-2"
            style="margin-right: 10px"
            >重置</el-button
          >
          <SettinUp
            :settype="3"
            :objSettinUpdata="objSettinUp"
            key="2"
          ></SettinUp>
        </div>
      </div>
      <div v-if="header_data_list_two.length > 0">
        <TableHeader
          ref="TableHeaderList_two"
          :header_data_list="header_data_list_two"
          :HeaderData="HeaderData_two"
          :propMap="propMap_two"
          :objheader="objheader_two"
          @orderIdNumsEvent="handleDeleteType_two"
          :operation_type="operation_type"
          @childEventJupway="handleJumpway"
          @handleClickDetail_three="handleClickDetail_three"
          @handleClickEdit_three="handleClickEdit_three"
          @clickabnormalFn_three="clickabnormalFn_three"
          particulars="waybillDistribution_detail"
          redact="waybillDistribution_amend_update"
          modification="abnormal_record_create"
        ></TableHeader>
      </div>
      <div
        style="
          display: flex;
          justify-content: flex-end;
          margin: 10px 0px 0px 0px;
        "
      >
        <el-pagination
          small
          background
          :current-page="pageNum"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalListNum"
          @size-change="handleSizeChangeLsz"
          @current-change="handleCurrentChangeLsz"
        />
      </div>
    </div>
    <div v-if="activeNameTab === 'three'">
      <!-- 订单操作 -->
      <div class="actions" style="margin-bottom: 10px">
        <div class="left">
          <template v-if="distributionSwitch">
            <el-button
              v-permission="'waybillDistribution_cancelFinish_update'"
              type="primary"
              plain
              data-tracker="P9-4"
              @click="handleClickCancel"
              >取消配送完成</el-button
            >
          </template>
          <template v-if="!distributionSwitch">
            <el-button
              type="primary"
              plain
              data-tracker="P9-4"
              @click="handleClickDelete"
              >删除</el-button
            >
          </template>
          <el-dropdown
            v-permission="'waybillDistribution_import_update'"
            @command="handleWaybillMessage"
            divided
            class="operation-drop"
          >
            <el-button type="primary" plain>
              导入<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu
              class="operation-drop"
              slot="dropdown"
              style="width: 150px"
            >
              <el-dropdown-item command="3">修改配送单信息</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <el-button
            v-permission="'waybill_distribution_export'"
            type="primary"
            :loading="isLoading"
            plain
            size="mini"
            @click="handleExport('1')"
            >导出</el-button
          >
        </div>
        <div class="right" style="display: flex">
          <el-button
            type="primary"
            @click.stop.native
            size="mini"
            icon="el-icon-refresh"
            @click="handleDeliveryReset"
            data-tracker="P9-2"
            style="margin-right: 10px"
            >重置</el-button
          >
          <SettinUp
            :settype="3"
            :objSettinUpdata="objSettinUp"
            key="3"
          ></SettinUp>
        </div>
      </div>
      <!-- 表格展示部分 -->
      <div v-if="header_data_list_three.length > 0">
        <TableHeader
          ref="TableHeaderList_three"
          :header_data_list="header_data_list_three"
          :HeaderData="HeaderData_three"
          :propMap="propMap_three"
          :objheader="objheader_three"
          :operation_type="operation_type"
          @orderIdNumsEvent="handleDeleteType_three"
          @handleClickDetail_three="handleClickDetail_three"
          @handleClickEdit_three="handleClickEdit_three"
          @clickabnormalFn_three="clickabnormalFn_three"
          @childEventJupway="handleJumpway"
          particulars="waybillDistribution_detail"
          redact="waybillDistribution_amend_update"
          modification="abnormal_record_create"
        ></TableHeader>
      </div>
      <div
        style="
          display: flex;
          justify-content: flex-end;
          margin: 10px 0px 0px 10px;
        "
      >
        <el-pagination
          small
          background
          :current-page="pageNumDel"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="pageSizeDel"
          layout="total, sizes, prev, pager, next, jumper"
          :total="totalListNumDel"
          @size-change="handleSizeChangeDel"
          @current-change="handleCurrentChangeDel"
        />
      </div>
    </div>
    <StepOperation
      v-if="mode === 'add'"
      :showDialog="showDialog"
      step="3"
      @close="handleCloseDialog"
      :ids="ids"
      :mode="mode"
      @closeDialog="handleCloseDialog"
    ></StepOperation>
    <StepOperation
      v-else
      :showDialog="showDialog"
      step="3"
      @close="handleCloseDialog"
      :id="nowId"
      :ids="ids"
      :mode="mode"
      @closeDialog="handleCloseDialog"
    ></StepOperation>
    <ImportDelivery
      :drawerDeliveryData="drawerDeliveryFlagShow"
      @drawerDeliveryShow="drawerDeliveryFlagShowFn"
    ></ImportDelivery>
  </div>
</template>

<script>
import TableHeader from "@/page/orderform/components/TableHeader/tableheader.vue";
import SettinUp from "@/page/orderform/components/settingUp/settingUp.vue";
import {
  DistributionstayListFn,
  getTransportsList,
  reqHandlersList,
  DistributionNoFinishList, //配送中
  DistributionFinishList, // 配送完成
  searchChargeData,
  //DistributionListFn,
  DistributionSuccessFn,
  DistributionCancelFn,
  DistributionDeleteFn,
  reqWebsiteList,
  waybillDistributionExport,
  waybillDistributionStayExport,
} from "@/api/waybill";
import Distribution from "./components/distribution.vue";
import StepOperation from "./components/stepOperation.vue";
import { dictionanryList, regionList } from "../material/common/common";
import { timestamp10 } from "@/utils/mUtils";
import { customerPeople } from "@/api/information";
import { organizationBox } from "@/api/organization";
import FinishTime from "./components/finishTime.vue";
import AbnormalModal from "./components/abnormalModal.vue";
import ImportDelivery from "../../components/waybillPop/ImportDelivery.vue";
import { sendClickTracker } from "@/utils/tracker";

export default {
  name: "distributionlistpage",
  data() {
    return {
      activeNameTab: "first",
      orderslength: "",
      collectDatalength: "",
      pickerOptions: {
        // 时间选择器的快选项
        shortcuts: [
          {
            text: "最近一周",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近一个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit("pick", [start, end]);
            },
          },
          {
            text: "最近三个月",
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit("pick", [start, end]);
            },
          },
        ],
      },
      orders: [],
      collectData: [],
      deliveryData: [],
      areaData2: [], //二级地址库
      paginations: {
        pageIndex: 1, // 当前位于哪页
        pageSize: 20, // 1页显示多少条
        pageSizes: [10, 20, 50, 100], //每页显示多少条
        total: 100,
        layout: "total, sizes, prev, pager, next, jumper", // 翻页属性
      },
      pageNum: 1, //目前在第几页
      totalListNum: 100, //列表总数
      pageSize: 20, //一页多少条
      pageNumDel: 1, //目前在第几页
      totalListNumDel: 100, //列表总数
      pageSizeDel: 20, //一页多少条
      statusArr: ["待配送", "配送中", "待签收"],
      options: [
        {
          value: "",
          label: "全部",
        },
        {
          value: "1",
          label: "超温",
        },
        {
          value: "2",
          label: "即将超温",
        },
        {
          value: "0",
          label: "正常",
        },
      ],
      propsBranchType: {
        emitPath: true,
        checkStrictly: true,
        value: "id",
        label: "branch_name",
        children: "next_level_data",
      },
      customerList: [], //所属客户
      creator_List: [], //创建人列表
      transportsType: [], //承运类型
      organizationBoxData: [],
      websiteListDQ: [],
      searchParams: {
        sender_city_id: [], ////发货人城市
        receiver_city_id: [], //收货人公司城市
        customer_area_id: "",
        from_area_id: "",
        to_area_id: "",
        from_network_id: [],
        to_network_id: [],
        time: [],
        customer_id: "",
        create_time: {
          start_time: 1664553600000,
          end_time: new Date().getTime(),
        },
        time: [1664553600000, new Date().getTime()],
        waybill_product_type: [],
      },
      ordersearch: {},
      searchDelivery: {},
      checkedIds: [],
      chargeData: [],
      motionData: [],
      showDialog: false, // 编辑弹框
      nowId: "",
      ids: [],
      statusEnum: [, "配送中", "配送完成"],
      thermosphereData: [],
      waybillIdNums: [],
      handleSelectionWaybillId: [],
      drawerDeliveryFlagShow: false,
      mode: "",
      statusArr: [
        "待揽收",
        "揽收中",
        "待创建干线",
        "待发车",
        "已发车",
        "待配送",
        "配送中",
        "待签收",
        "待回单",
        "待回单签收",
        "已完结",
      ], //运单状态
      isLoading: false,
      header_data_list: [],
      propMap: {},
      obj_list: {},
      HeaderData: [],
      orders_list: [],
      header_data_list_two: [],
      propMap_two: {},
      obj_list_two: {},
      HeaderData_two: [],
      orders_list_two: [],
      header_data_list_three: [],
      propMap_three: {},
      obj_list_three: {},
      HeaderData_three: [],
      orders_list_three: [],
      operation_type: "1",
      derive_list: {},
      distributionSwitch: false,
    };
  },
  components: {
    Distribution,
    StepOperation,
    ImportDelivery,
    TableHeader,
    SettinUp,
  },

  mounted() {
    this.getDistributionListFn();
    this.provincectiy(); //地址库
    this.getThermosphereType(); //承运类型
    this.organizationBoxFn();
    this.getDictionary();
    this.getWebsiteListDQFn();
    this.distributionSwitch = this.getSwitch();
  },
  watch: {
    $route: {
      handler(newV, oldV) {
        if (this.$route.query.type == 0) {
          const el = {
            name: "first",
          };
          this.changehandle(el);
          this.activeNameTab = "first";
        } else if (this.$route.query.type == 1) {
          const el = {
            name: "second",
          };
          this.changehandle(el);
          this.activeNameTab = "second";
        } else if (this.$route.query.type == 2) {
          const el = {
            name: "three",
          };
          this.changehandle(el);
          this.activeNameTab = "three";
        }
        // console.log(this.$route.query.type, "this.$route.query.type");
      },
      immediate: true,
      deep: true,
    },
  },
  computed: {},
  methods: {
    getSwitch() {
      // 0-自动配送完成 1-正常
      const item = (this.$store.state.user.setting_list || []).find(
        (item) => item.item_name === "distribution_finish_switch"
      );
      return item.item_value === "1";
    },
    handleExport(status) {
      this.isLoading = true;
      if (status === "0" || status === "1") {
        let params;
        if (status === "0") {
          params = {
            ...this.obj_list_two,
          };
        } else {
          params = {
            ...this.obj_list_three,
          };
        }
        waybillDistributionExport({
          ...params,
          ids: (this.checkedIds || []).map(Number),
          status: status,
        }).then((res) => {
          if (res.code === 10000) {
            this.reqUrl = "https://" + res.data.loaded_url;
            window.open(this.reqUrl);
            this.isLoading = false;
          }
        });
      } else if (status === "2") {
        waybillDistributionStayExport({
          ...this.derive_list,
          ids: this.waybillIdNums.map(Number),
        }).then((res) => {
          if (res.code === 10000) {
            this.reqUrl = "https://" + res.data.loaded_url;
            window.open(this.reqUrl);
            this.isLoading = false;
          }
        });
      }
      sendClickTracker("P9-12");
    },
    //获取区域
    async getWebsiteListDQFn() {
      let result = await reqWebsiteList({ branch_type: "3" });
      this.websiteListDQ = result.data;
    },
    remoteMethod(nickname, key, params = {}) {
      const branch_id = this.$store.state.user.branch_id;
      searchChargeData({ branch_id, nickname, ...params }).then((res) => {
        if (key === "operation") {
          this.motionData = res.data;
        } else {
          this.chargeData = res.data;
        }
      });
    },
    handleclick(row, column, cell, event) {
      this.$set(row, "showAll", true);
    },
    handleclickleave(row, column, cell, event) {
      this.$set(row, "showAll", false);
    },
    //获取选中的运单（待揽收）
    handleSelectionWaybillChange(val) {
      this.handleSelectionWaybillId = val;
      if (val.length > 0) {
        for (var i = 0; i < this.handleSelectionWaybillId.length; i++) {
          this.waybillIdNums = this.handleSelectionWaybillId.map((item) =>
            Number(item.id)
          );
        }
      } else {
        this.waybillIdNums = [];
      }
    },
    //创建揽收单
    handleClickAdd() {
      this.mode = "add";
      this.ids = this.waybillIdNums.map(Number);
      this.showDialog = true;
    },
    // 用户列表接口
    Pagecreator() {
      reqHandlersList().then((res) => {
        this.creator_List = res.data;
      });
    },
    //获取分级组织
    organizationBoxFn() {
      let data = {
        show_employee: false, // 是否展示员工信息
        not_show_first_branch: 1,
      };
      organizationBox(data).then((res) => {
        if (res.code === 10000) {
          this.organizationBoxData = res.data;
        }
      });
    },
    searchCustomerList(query) {
      //获取客户
      if (query !== "") {
        setTimeout(async () => {
          // let { router, router_id } = this.formData;
          let result = await customerPeople({
            name: query, // 名称
            id: "",
            is_send: "",
            is_receive: "",
          });
          this.customerList = result.data;
        }, 200);
      } else {
        this.customerList = [];
      }
    },
    // 地址库
    provincectiy() {
      regionList(0).then((res) => {
        this.childeprovicectiy(res.data);
      });
    },
    // 地址库改为二级
    childeprovicectiy(data) {
      data.forEach((item) => {
        item.next_level_data.forEach((iten) => {
          iten.next_level_data = undefined;
        });
      });
      this.areaData2 = data;
    },
    // 承运类型
    async getThermosphereType() {
      let result2 = await getTransportsList({ is_all: false });
      this.transportsType = result2.data.data;
    },
    // 创建时间
    handleDateChange(val) {
      if (val) {
        this.searchParams.create_time.start_time = timestamp10(val[0]);
        this.searchParams.create_time.end_time = timestamp10(val[1]);
      } else {
        this.searchParams.create_time.start_time = "";
        this.searchParams.create_time.end_time = "";
      }
    },
    handleWaybillMessage(val) {
      const Fn = ["drawerDelivery"][val];
      this[Fn] && this[Fn]();
      if (val == "3") {
        this.drawerDelivery();
        sendClickTracker("P9-11");
      }
    },
    //配送费用修改
    drawerDelivery() {
      this.drawerDeliveryFlagShow = true;
    },
    drawerDeliveryFlagShowFn(data) {
      this.drawerDeliveryFlagShow = data;
    },
    changehandle(el) {
      if (el.name == "first") {
        this.getDistributionListFn();
      } else if (el.name == "second") {
        this.getDistributionNoFinishListFn();
      } else {
        // console.log('el.name == "three"');
        this.getDistributionFinishListFn();
      }
    },
    getStaySearchParams() {
      return {
        page: this.paginations.pageIndex,
        page_size: this.paginations.pageSize,
        header_id: 1 + "",
        ...this.obj_list,
        // ...this.searchParams,
        create_time: {
          start_time: (this.searchParams.create_time.start_time + "").slice(
            0,
            10
          ),
          end_time: (this.searchParams.create_time.end_time + "").slice(0, 10),
        },
        // customer_id: this.searchParams.customer_id + "",
        // from_network_id: "",
        // to_network_id: "",
        // waybill_product_type:
        //   this.searchParams.waybill_product_type.map(Number),
        // from_network_id_list:
        //   this.searchParams.from_network_id != ""
        //     ? [
        //         this.searchParams.from_network_id[
        //           this.searchParams.from_network_id.length - 1
        //         ],
        //       ]
        //     : [],
        // to_network_id_list:
        //   this.searchParams.to_network_id != ""
        //     ? [
        //         this.searchParams.to_network_id[
        //           this.searchParams.to_network_id.length - 1
        //         ],
        //       ]
        //     : [],
        // from_area_id: this.searchParams.from_area_id + "",
        // to_area_id: this.searchParams.to_area_id + "",
        // customer_area_id: this.searchParams.customer_area_id + "",
        // sender_city_id:
        //   this.searchParams.sender_city_id[1] == "undefined"
        //     ? 0
        //     : this.searchParams.sender_city_id[1],
        // receiver_city_id:
        //   this.searchParams.receiver_city_id[1] == "undefined"
        //     ? 0
        //     : this.searchParams.receiver_city_id[1],
      };
    },
    //待配送
    getDistributionListFn() {
      const params = this.getStaySearchParams();
      this.derive_list = this.getStaySearchParams();
      DistributionstayListFn(params).then((res) => {
        this.orders_list = res.data.data == null ? [] : res.data.data;
        this.orders_list.unshift({});
        // console.log(this.orders_list, "jfalksjdl");
        this.header_data_list = this.orders_list;
        this.HeaderData = res.data.item_list;
        this.Fntransformation(this.HeaderData);
        this.paginations.total = res.data.total;
        this.orderslength = res.data.total;
        // this.$refs.multipleTabledistribution.clearSelection();
      });
    },
    objheader(obj) {
      var data = {
        header_id: 1 + "",
        ...obj,
      };
      this.obj_list = obj;
      this.derive_list = obj;
      DistributionstayListFn(data).then((res) => {
        if (res.code === 10000 && res.data.data !== null) {
          this.orders_list = res.data.data == null ? [] : res.data.data;
          this.orders_list.unshift({});
          this.header_data_list = this.orders_list;
          this.paginations.total = res.data.total;
          this.orderslength = res.data.total;
          this.paginations.pageSize = 20;
          //  this.$emit("valueChanged", res.data.total);
        } else {
          this.header_data_list = [{}];
          this.paginations.total = 0;
          this.orderslength = 0;
        }
      });
    },
    handleDelete(index, id, type) {
      this.handleJumpDetail(id);
    },
    handleDeleteType(value) {
      this.waybillIdNums = value.map(String);
    },
    // 隐射函数
    Fntransformation(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap = result;
    },
    //配送中翻页
    handleSizeChangeLsz(val) {
      this.pageSize = val; //一页多少条
      this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
    },
    handleCurrentChangeLsz(val) {
      this.pageNum = val; //第多少页
      this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
    },
    // 配送中参数
    getSearchParams0() {
      return {
        page: this.pageNum,
        page_size: this.pageSize,
        header_id: 3 + "",
        ...this.orders_list_two,
        // ...this.ordersearch,
        // to_network_id:
        //   this.ordersearch.to_network_id == undefined
        //     ? ""
        //     : this.ordersearch.to_network_id[
        //         this.ordersearch.to_network_id.length - 1
        //       ] + "",
      };
    },
    // 配送完成参数
    getSearchParams1() {
      return {
        page: this.pageNumDel,
        page_size: this.pageSizeDel,
        header_id: 3 + "",
        ...this.orders_list_three,
        // ...this.searchDelivery,
        // to_network_id:
        //   this.searchDelivery.to_network_id == undefined
        //     ? ""
        //     : this.searchDelivery.to_network_id[
        //         this.searchDelivery.to_network_id.length - 1
        //       ] + "",
      };
    },
    //配送中
    getDistributionNoFinishListFn() {
      const params = this.getSearchParams0();
      DistributionNoFinishList(params).then((res) => {
        if (res.code == 10000 && res.data.data != null) {
          this.orders_list_two = res.data.data == null ? [] : res.data.data;
          this.orders_list_two.unshift({});
          this.header_data_list_two = this.orders_list_two;
          this.HeaderData_two = res.data.item_list;
          this.Fntransformation_two(this.HeaderData_two);
          this.totalListNum = res.data.total;
          this.pageSize = res.data.page_size;
          this.collectDatalength = res.data.total;
        } else {
          this.collectData = [];
          this.pageNum = 1;
          this.pageSize = 20;
          this.totalListNum = 0;
        }
      });
    },
    objheader_two(obj) {
      this.orders_list_two = [];
      var data = {
        page: this.pageNumDel,
        page_size: this.pageSizeDel,
        header_id: 3 + "",
        ...obj,
      };
      this.obj_list_two = obj;
      DistributionNoFinishList(data).then((res) => {
        // this.header_data_list = res.data.list
        if (res.code === 10000 && res.data.data !== null) {
          this.orders_list_two = res.data.data == null ? [] : res.data.data;
          this.orders_list_two.unshift({});
          this.header_data_list_two = this.orders_list_two;
          this.paginations.total = res.data.total;

          this.$emit("valueChanged", res.data.total);
          this.totalListNum = res.data.total;
          this.pageSize = res.data.page_size;
          this.collectDatalength = res.data.total;
        } else {
          this.header_data_list_two = [{}];
          this.pageNum = 1;
          this.pageSize = 20;
          this.totalListNum = 0;
          this.collectDatalength = 0;
        }
      });
    },
    handleDelete_two(index, id, type) {
      this.handleJump(id);
      // console.log(id, "fjskldj");
    },
    handleDeleteType_two(value) {
      this.checkedIds = value.map(String);
    },
    // 隐射函数
    Fntransformation_two(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap_two = result;
    },
    // 配送完成
    handleSizeChangeDel(val) {
      this.pageSizeDel = val; //一页多少条
      this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
    },
    handleCurrentChangeDel(val) {
      this.pageNumDel = val; //第多少页
      this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
    },
    //配送完成 API
    getDistributionFinishListFn() {
      const params = this.getSearchParams1();
      // console.log("配送完成");
      DistributionFinishList(params).then((res) => {
        if (res.code == 10000 && res.data.data != null) {
          this.orders_list_three = res.data.data == null ? [] : res.data.data;
          this.orders_list_three.unshift({});
          this.header_data_list_three = this.orders_list_three;
          this.HeaderData_three = res.data.item_list;
          this.Fntransformation_three(this.HeaderData_three);
          this.pageNumDel = res.data.page;
          this.totalListNumDel = res.data.total;
          this.pageSizeDel = res.data.page_size;
        } else {
          this.deliveryData = [];
          this.pageNumDel = 1;
          this.pageSizeDel = 20;
          this.totalListNumDel = 0;
        }
      });
    },
    objheader_three(obj) {
      this.orders_list_three = [];
      var data = {
        page: this.pageNumDel,
        page_size: this.pageSizeDel,
        header_id: 3 + "",
        ...obj,
      };
      this.obj_list_three = obj;
      DistributionFinishList(data).then((res) => {
        // this.header_data_list = res.data.list
        if (res.code === 10000 && res.data.data !== null) {
          this.orders_list_three = res.data.data == null ? [] : res.data.data;
          this.orders_list_three.unshift({});
          this.header_data_list_three = this.orders_list_three;
          this.totalListNumDel = res.data.total;
          this.pageSizeDel = 20;
          //  this.$emit("valueChanged", res.data.total);
        } else {
          this.header_data_list_three = [{}];
          this.totalListNumDel = res.data.total;
        }
      });
    },
    handleDelete_three(index, id, type) {
      this.handleJump(id);
    },
    handleDeleteType_three(value) {
      this.checkedIds = value.map(String);
    },
    // 隐射函数
    Fntransformation_three(obj) {
      const result = {};
      for (const prop in obj) {
        if (obj.hasOwnProperty(prop)) {
          if (obj[prop].send_name !== "") {
            result[obj[prop].name] = obj[prop].show_name;
          } else {
            result[obj[prop].name] = obj[prop].name;
          }
        }
      }
      this.propMap_three = result;
    },
    async handleJump(scope, index) {
      // console.log(scope, "fjasldkfj");
      const waybill_id_list = scope.row.waybill_id_list || [];
      const id = waybill_id_list[index];
      let text = this.$router.resolve({
        name: "waybillDetail",
        query: { id, activeName: "1" },
      });
      window.open(text.href, "_blank");
    },
    async handleJumpDetail(scope) {
      const checkedOrder = scope.id;
      const id = checkedOrder;
      let text = this.$router.resolve({
        name: "waybillDetail",
        query: { id, activeName: "1" },
      });
      window.open(text.href, "_blank");
    },
    // handleJumpHref(scope) {
    //   const id = scope.id;
    //   let text = this.$router.resolve({
    //     name: "waybillDetail",
    //     query: { id, activeName: "1" },
    //   });
    //   window.open(text.href, "_blank");
    // },
    handleSizeChange(val) {
      this.paginations.pageSize = val;
      this.getDistributionListFn();
    },
    handleCurrentChange(val) {
      this.paginations.pageIndex = val;
      this.getDistributionListFn();
    },
    handleSelectionChange(val) {
      this.checkedIds = val.map((item) => item.collect_id);
    },
    handleClickEdit({ collect_id, waybill_id_list }) {
      this.mode = "edit";
      this.nowId = Number(collect_id);
      this.ids = (waybill_id_list || []).map(Number);
      this.showDialog = true;
    },
    handleClickDetail({ collect_id, waybill_id_list }) {
      this.mode = "detail";
      this.nowId = Number(collect_id);
      this.ids = (waybill_id_list || []).map(Number);
      this.showDialog = true;
    },
    handleCloseDialog(isUpdate = true) {
      this.showDialog = false;
      isUpdate && this.getDistributionListFn();
      isUpdate &&
        this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
      isUpdate &&
        this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
    },
    handleSearch() {
      this.paginations.pageIndex = 1;
      this.getDistributionListFn();
    },
    handleReset() {
      this.$refs.TableHeaderList_one.childMethod();
      this.paginations.pageIndex = 1;
      this.getDistributionListFn();
    },
    handleOrderSearch() {
      this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
    },
    handleSearchReset() {
      // this.ordersearch = {};
      this.$refs.TableHeaderList_two.childMethod();
      this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
    },
    handleDeliverySearch() {
      this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
    },
    handleDeliveryReset() {
      this.$refs.TableHeaderList_three.childMethod();
      this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
    },
    handleFinish(time) {
      DistributionSuccessFn({
        ids: this.checkedIds.map(Number),
        finish_time: time,
      }).then((res) => {
        if (res.code === 10000) {
          this.$message({
            message: "配送完成",
            type: "success",
          });
          this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
        } else {
          this.$alert(res.message, "错误提示");
        }
      });
    },
    handleClickSuc() {
      const title = "配送完成";
      this.$msgbox({
        message: (
          <FinishTime
            title={title}
            key={Date.now()}
            hanldeOk={this.handleFinish}
          ></FinishTime>
        ),
        customClass: "temperature_msg",
        showConfirmButton: false,
        showCancelButton: false,
        showClose: true,
        title,
      });
    },
    handleClickCancel() {
      DistributionCancelFn({ ids: this.checkedIds.map(Number) }).then((res) => {
        if (res.code === 10000) {
          this.$message({
            message: "取消配送成功",
            type: "success",
          });
          this.getDistributionFinishListFn(this.pageNumDel, this.pageSizeDel);
        } else {
          this.$alert(res.message, "错误提示");
        }
      });
    },
    handleClickDelete() {
      DistributionDeleteFn({ ids: this.checkedIds.map(Number) }).then((res) => {
        if (res.code === 10000) {
          this.$message({
            message: "删除成功",
            type: "success",
          });
          this.getDistributionNoFinishListFn(this.pageNum, this.pageSize);
        }
      });
    },
    //异常操作
    clickabnormalFn(valData) {
      const { waybill_id_list = [], collect_id } = valData;
      this.$msgbox({
        title: "提交异常",
        message: (
          <AbnormalModal
            key={Math.random()}
            step={3}
            waybillIds={waybill_id_list.map(String)}
            nodeId={collect_id}
            style="width:600px"
          ></AbnormalModal>
        ),
        customClass: "temperature_msg",
        showConfirmButton: false,
        showCancelButton: false,
        closeOnClickModal: false,
        showClose: true,
      });
    },
    getDictionary() {
      dictionanryList(["thermosphere"]).then((res) => {
        const data = res.data.list["thermosphere"];
        data.forEach((item) => {
          const { item_code, item_name } = item;
          this.thermosphereData[item_code] = item_name;
        });
      });
    },
    handleClickDetail_three(val) {
      this.handleClickDetail(val);
    },
    handleClickEdit_three(val) {
      this.handleClickEdit(val);
    },
    clickabnormalFn_three(val) {
      this.clickabnormalFn(val);
    },
    handleJumpway(scope, index) {
      // console.log(scope, "jflaskdj");
      // console.log(index, "dslkjlk");
      this.handleJump_list(scope, index);
    },
    handleJump_list(scope, index) {
      // console.log(scope, index);
      const waybill_id_list = scope.row.waybill_list || [];

      const id = waybill_id_list[index].waybill_id;

      let text = this.$router.resolve({
        name: "waybillDetail",
        query: { id, activeName: "1" },
      });
      window.open(text.href, "_blank");
    },
    objSettinUp() {
      this.getDistributionNoFinishListFn();
      this.getDistributionFinishListFn();
    },
  },
};
</script>

<style lang="less" scoped>
// /deep/ .el-tabs__nav-wrap {
//   left: -154px;
// }

/deep/.badge_item .el-badge__content.is-fixed {
  top: 6px;
  left: 0px;
}
.allOrderContainer {
  padding: 10px 15px;
  background-color: #fff;
  ::v-deep .el-tabs--border-card {
    -webkit-box-shadow: none;
    border: none;
  }
  .orderHeader {
    background-color: #fff;
    .orderSearch {
      ::v-deep .el-form--inline .el-form-item__content {
        vertical-align: middle;
      }
      ::v-deep .el-collapse {
        border-top: none;
        border-bottom: none;
      }
    }
  }

  .actions {
    display: flex;
    justify-content: space-between;
    flex-wrap: wrap;
    width: 100%;
    background-color: #fff;
    .el-button + .el-dropdown,
    .el-dropdown + .el-button {
      margin-left: 10px;
    }
  }
}
</style>
